home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / X-TREE.TXT < prev    next >
Text File  |  1996-07-04  |  7KB  |  134 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   X-TREE  .TXT ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16. $endif
  17.  
  18. DOS sends file and disk data back through a series of interrupts and in
  19. a buffer called the DTA ( Data Transfer Area ). There are several low
  20. level DOS calls in this library that are not completely documented here
  21. due to their very low level nature. The services that they provide are,
  22. however, all available to you through other, higher order functions and
  23. routines. If you wish to experiment with them they are listed with brief
  24. explanations as to their functions on the last page of this file.
  25.  
  26. ANATOMY OF A BYTE:   &b00100001
  27.                        │││││││└─── bit 0 value   1
  28.                        ││││││└──── bit 1 value   2
  29.                        │││││└───── bit 2 value   4
  30.                        ││││└────── bit 3 value   8
  31.                        │││└─────── bit 4 value  16
  32.                        ││└──────── bit 5 value  32
  33.                        │└───────── bit 6 value  64
  34.                        └────────── bit 7 value 128
  35.  
  36. This is a good time to go into BITMAPs. As DOS uses them extensively you
  37. need to have some idea of what is going on.  So, let's take a minute and
  38. get you up to speed on BITs and BYTEs.
  39.  
  40. The easiest way to work with bit-maps is to use BINARY numbers.  And our
  41. example ( above ) is displayed in this format.  Notice that the BYTE has
  42. 8 bits and each bit has a position number ( 7 -> 0 ) and a corresponding
  43. decimal value. Bits 0 and 5 are "ON" so the decimal value of the byte is
  44. 33. Which can either be 1) the value 33
  45.                         2) the character "!"
  46.                         3) 2 yes and 6 no answers
  47.                         4) 1 of 256 possible answers
  48.  
  49. Let's say I've got a list of 5 jobs. Any or all of them can be done and I
  50. only need to know which, if any, you want done. To DIM a BYTE array
  51. Jobs?( 0:4 ) would do the trick,  so would a string of five "Y"s and "N"s
  52. but all this can be put into a single BYTE and still have room left over!
  53.  
  54.        EXAMPLE:   Jobs? = &b00010101
  55.                   IF Jobs? AND &b00000001 THEN
  56.                     ' bit 0 is "ON" in both numbers so we'll do this one
  57.                   END IF
  58.                   IF Jobs? AND &b00000010 THEN
  59.                     ' bit 1 is "OFF" in Jobs? so this one is skipped
  60.                   END IF
  61.  
  62. When working with "AND", "OR", "XOR", etc. you need 2 bit-maps.  The one
  63. on the right is the controller or MASK. It lets the program determine if
  64. the task is to be done or not.   As you can see by the example above the
  65. 0th, 2nd, and 4th IFs will be processed and the rest will not. You could
  66. also have asked: IF ( Jobs? AND &b00010001 ) THEN .... and it would have
  67. been just as correct.
  68.  
  69. Of course, if you need more than 8 selections you can use WORDs that
  70. have 16 bits or DWORDs that have 32 bits.  Think of the savings involved
  71. if you had to store 32 answers to Y/N questions: you could store 32bytes
  72. in an ARRAY or 4bytes in a BIT-MAP!
  73.  
  74. DOS, however, goes one step further in using available space.  They have
  75. a habit of assigning a number of bits to hold a value then  "SHIFT" bits
  76. and mask bits off ( XOR ) to get to the particular set of bits they want
  77. the value for.
  78.   EXAMPLE:  &b0000000000000000    FILE DATE
  79.               └─────┤└──┤└───┴─── DAY   bits 0 ->  4
  80.                     │   └──────── MONTH bits 5 ->  8
  81.                     └──────────── YEAR  bits 9 -> 15
  82.  
  83.   EXAMPLE:  &b0000000000000000    FILE TIME
  84.               └───┤└────┤└───┴─── SECONDS bits  0 ->  4 ( * 2 )
  85.                   │     └──────── MINUTES bits  5 -> 10
  86.                   └────────────── HOURS   bits 11 -> 15
  87.  
  88. These may not be the smartest way to store  the data but in ASSEMBLY it
  89. causes a lot less problem than it does in BASIC and that's the way things
  90. are! End of lesson! I hope we have made things a little clearer for you.
  91. You really don't need any of this when working with the routines in
  92. DAS-2L2S.PBL as I have provided higher order functions that will return
  93. numbers more "humanised" for you to use.  Bit mapping and masking is,
  94. however, a very powerful tool to the programmer and you should take the
  95. time to become familiar with it.
  96.  
  97. ' ──────────────────────────────────────────────────────────────────────────
  98. ' ─────────                                                       ──────────
  99. ' ──────────────────────────────────────────────────────────────────────────
  100.  
  101. It is not, normally, my way to leave those who don't understand or know how
  102. to use one of the routines in the dark but some of the low-level functions
  103. that support of the higher-level functions are made available to those who
  104. understand them. It is way beyond the capability of this library to teach
  105. their use. I do not mean to discourage anyone but I'm afraid I have to leave
  106. you to your own devices here:(
  107.  
  108. A word of caution: before attempting to use them learn where the reset button
  109.                    is on your computer, you'll be needing it!
  110.  
  111. fDIRfirstFILE%  locate first file that matches Mask$
  112. fDIRnextFILE%   locate next file in order
  113. fDIRfile$       returns the file's name
  114. fDIRattr?       returns the file's attribute value
  115. fGetDTA$        read DTA into a string
  116.  PutDTA         replace/overwrite DTA
  117. fDTAPTR???      FARPOINTER to the DTA
  118. fDIRtime??      a file's time in DOS style
  119. fDIRdate??      a file's date in DOS style
  120. fDIRsize&       a file's size in bytes
  121.  DIRtime        a file's time in H,M,S
  122.  DIRdate        a file's date in Y,M,D
  123. fGetFirstDir%
  124. fGetNextDir%
  125. fSubDirName$
  126.  
  127. File Attributes:                    &b00111111    BIT-MAP
  128.                   32 Archive File ──────┘│││││
  129.                   16 Directory    ───────┘││││
  130.                    8 Volume Label ────────┘│││
  131.                    4 System File  ─────────┘││
  132.                    2 Hidden File  ──────────┘│
  133.                    1 Read Only    ───────────┘
  134.